function fnGetXMLHttpObject(){
	var http_req = null;	   
	if (window.XMLHttpRequest)
	{ // Mozilla, Safari,...
		http_req = new XMLHttpRequest();
		
		if (http_req.overrideMimeType)
		{
			http_req.overrideMimeType('text/xml');
		}
		return http_req;
	} 
	else if (window.ActiveXObject)
	{ // IE		           
		try {
			http_req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try {
				http_req = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(e){}
		}
		return http_req;
	}
	
	return http_req;
}

function selectAll(){
	for(var i=0;i<document.getElementsByName("ChkAppln").length;i++)	{
		if(document.getElementById("chkbxSelectAll").checked){
		document.getElementsByName("ChkAppln")[i].checked=true;
		}
		else{
		document.getElementsByName("ChkAppln")[i].checked=false; 
		}
	}
}

function fnEditUserDetails(userId){
	document.userMasterForm.method = "POST";
	document.userMasterForm.action="/Yunysha/userMaster.do?edit="+userId;
	document.userMasterForm.submit();
}

function fnDeleteUser(userId){
	document.assesmentMasterForm.method = "POST";
	document.assesmentMasterForm.action="/Yunusha/userMaster.do?delete="+userId;
	document.assesmentMasterForm.submit();
}

function fnCreateUser(){
	document.userMasterForm.method = "POST";
	document.userMasterForm.action="/Yunysha/userMaster.do?edit=0";
	document.userMasterForm.submit();
}


function saveUserDetails(){
	document.userMasterForm.method = "POST";
	document.userMasterForm.action="/Yunysha/userMasterSave.do";
	document.userMasterForm.submit();
}

function fnCloseImage(){
	if(document.getElementById('messageBox')!=null){
		document.getElementById('messageBox').style.display="none";
	}
}

function fnRetrieveSearchFilter(value,tableId){
	if(value.length>2){
		var http_request=fnGetXMLHttpObject();
		var searchName = document.getElementById('searchUserName').value;
		var searchMobile = document.getElementById('searchUserMobile').value;
		var searchEmail = document.getElementById('searchUserEmail').value;
		var parameters="userList,##,"+searchName+",##,"+searchMobile+",##,"+searchEmail+",##,0";
		
		if(http_request!=null){
			var pValidationServlet = "SearchFilterServlet"; 
			   
	    	http_request.open('POST',pValidationServlet,true);       
			http_request.onreadystatechange = function() { fnPopulateSearchData(http_request,tableId); }; 	 	                    
			http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");               
			http_request.send("parameters="+encodeURI(parameters));
		}
	}
}

function fnPopulateSearchData(http_request,tableId){
	if (http_request.readyState == 4){
		if (http_request.status == 200) {
			if(http_request.responseText != null){
				var responseDoc= http_request.responseXML;
				var htmlName = responseDoc.getElementsByTagName("RESPONSE");
				var fieldCheck=htmlName[0].getAttribute("tableId");
				var recordCount = htmlName[0].getAttribute("noOfRecords");
				var docs = responseDoc.getElementsByTagName("ROW");
				var noOfDocuments = docs.length;
				var table = document.getElementById(tableId);
				for(var i = table.rows.length - 1; i > 0; i--)
				{
    				table.deleteRow(i);
				}
				if(noOfDocuments > 0){	
					for(var count=0;count<noOfDocuments;count++){
						var row=table.insertRow(count+1);
						var docFields=docs[count].getElementsByTagName("FIELD");
						var fieldValue = docFields[0].firstChild.nodeValue;
						var cell1=row.insertCell(0);
						cell1.innerHTML = '<span class="checkbox">'+
							'<input type="checkbox"	name="ChkAppln" id="Chk'+fieldValue+'" value="'+fieldValue+'" /></span>';
						cell1.class="rghtbdr check";
						for(var fieldCount=1;fieldCount<docFields.length;fieldCount++){
							var fieldValue = docFields[fieldCount].firstChild.nodeValue;
							var cell1=row.insertCell(fieldCount);
							cell1.innerHTML = fieldValue;
						}
						var fieldValue = docFields[fieldCount++].firstChild.nodeValue;
						var cell1=row.insertCell(fieldCount++);
						cell1.innerHTML = '<div><a class="link_butt" href="javascript:fnEditUserDetails("'+fieldValue+'");"> '+
						'<img src="images/edit_icon.gif" title="Edit" /></a></div><div><a class="link_butt" '+
						' href="javascript:fnDeleteUser("'+fieldValue+'");"> <img src="images/delete_icon.gif" title="Delete" /></a></div>';
						cell1.class="rghtbdr check";
					}
				} else {
					var row=document.getElementById(tableId).insertRow(1);
					var cell1=row.insertCell(0);
					cell1.innerHTML = "No records found";
				}
			}
		}
	}
}